package com.briup.estore.dao.impl;

import com.briup.estore.common.constant.ExceptionMsgEnum;
import com.briup.estore.common.dto.AddressAddDTO;
import com.briup.estore.common.dto.AddressUpdateDTO;
import com.briup.estore.common.exception.EstoreException;
import com.briup.estore.common.pojo.Address;
import com.briup.estore.common.utils.JDBCUtils;
import com.briup.estore.dao.AddressDao;

import java.util.List;

/**
 * @Author briup-adam
 * @Date 2023/8/3 下午2:58
 * @Description  对表【es_address】的数据库操作
 **/

public class AddressDaoImpl implements AddressDao {
    @Override
    public List<Address> findByUserId(Integer userId) {
            List<Address> list = JDBCUtils.findMany("select *   from  es_address where user_id =? ;", Address.class, userId);
            return list;


    }

    @Override
    public void update(Address add) {
            JDBCUtils.DML("update es_address set receiver_name=?,urban_addr=?,detail_addr=?,phone=? where id=?;",add.getReceiverName(),add.getUrbanAddr(),add.getDetailAddr(),add.getPhone(),add.getId());


    }

    @Override
    public void save(Address add) {
            JDBCUtils.DML("insert into es_address(receiver_name,urban_addr, detail_addr,phone,user_id) values(?,?,?,?,?);",
                    add.getReceiverName(),add.getUrbanAddr(),add.getDetailAddr(),add.getPhone(),add.getUserId());

    }


    @Override
    public void deleteById(Integer id) {
            JDBCUtils.DML("delete from es_address where id=?;",id);

    }
}
